<template>
  <div class="security-center">
    <div class="security-header">
      <h1>安全中心</h1>
      <p class="security-subtitle">完成系统建议的安全设置提升账户安全</p>
    </div>

    <!-- 主要安全设置 -->
    <div class="security-section">
      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><Key /></el-icon>
            <span>通行密钥</span>
          </div>
          <el-button type="default" size="small" class="custom-button">设置</el-button>
        </div>
        <p class="security-item-desc">无需密码或验证码，快捷登录更安全</p>
      </div>

      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><Phone /></el-icon>
            <span>手机验证</span>
          </div>
          <el-button type="default" size="small" class="custom-button">设置</el-button>
        </div>
        <p class="security-item-desc">通过短信、WhatsApp 或语音通话获取验证码，用于登录等功能</p>
      </div>

      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><Lock /></el-icon>
            <span>身份验证 App</span>
          </div>
          <el-button type="default" size="small" class="custom-button">设置</el-button>
        </div>
        <p class="security-item-desc">使用验证码进行登录等操作</p>
      </div>

      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><Shield /></el-icon>
            <span>防钓鱼码</span>
          </div>
          <el-button type="default" size="small" class="custom-button">设置</el-button>
        </div>
        <p class="security-item-desc">给来自欧易的邮件添加一组独特代码以便识别</p>
      </div>
    </div>

    <!-- 验证方式 -->
    <div class="security-section">
      <h2 class="section-title">验证方式</h2>
      
      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><Message /></el-icon>
            <span>邮箱验证</span>
          </div>
          <el-button type="default" size="small" class="custom-button">更改邮箱</el-button>
        </div>
        <p class="security-item-desc">通过邮箱获取验证码，用于登录等功能</p>
        <p class="security-item-value">{{ maskEmail(userInfo.email) }}</p>
      </div>

      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><Lock /></el-icon>
            <span>登录密码</span>
          </div>
          <el-button type="default" size="small" class="custom-button">更换密码</el-button>
        </div>
        <p class="security-item-desc">通过设置登录密码，您将可以使用账号和登录密码直接登录</p>
        <p class="security-item-value">********</p>
      </div>
    </div>

    <!-- 高级安全设置 -->
    <div class="security-section">
      <h2 class="section-title">高级安全设置</h2>

      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><Monitor /></el-icon>
            <span>设备管理</span>
          </div>
          <el-button type="default" size="small" class="custom-button">管理</el-button>
        </div>
        <p class="security-item-desc">管理并查看最近的登录活动和设备信息</p>
      </div>

      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><Coin /></el-icon>
            <span>交易权限</span>
          </div>
          <el-switch
            v-model="tradingEnabled"
            active-text="已开启"
            inactive-text="已关闭"
            class="custom-switch"
          />
        </div>
        <p class="security-item-desc">设置可交易的市场类型和币种</p>
      </div>
    </div>

    <!-- 账号管理 -->
    <div class="security-section">
      <h2 class="section-title">账号管理</h2>

      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><Warning /></el-icon>
            <span>冻结账号</span>
          </div>
          <el-button type="default" size="small" class="custom-button danger">冻结</el-button>
        </div>
        <p class="security-item-desc">您的账号将暂时冻结，如需解冻请先重新登录</p>
      </div>

      <div class="security-item">
        <div class="security-item-header">
          <div class="security-item-title">
            <el-icon><CircleClose /></el-icon>
            <span>关闭账号</span>
          </div>
          <el-button type="default" size="small" class="custom-button danger">关闭</el-button>
        </div>
        <p class="security-item-desc">一旦您选择关闭账号，账号将会永久关闭且无法恢复</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import {onMounted, ref} from 'vue'
import userInfoStore from "@/stores/userInfo";
const userInfo = ref({})
import {
  Key,
  Phone,
  Lock,
  Shield,
  Message,
  Monitor,
  Coin,
  Warning,
  CircleClose
} from '@element-plus/icons-vue'
const tradingEnabled = ref(false)
onMounted(() => {
  userInfo.value = userInfoStore().info
})

// 邮箱脱敏
const maskEmail = (email) => {
  if (!email) return ''
  const [name, domain] = email.split('@')
  const maskedName = name.slice(0, 3) + '***'
  return `${maskedName}@${domain}`
}

</script>

<style scoped>
.security-center {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 20px;
}

.security-header {
  margin-bottom: 40px;
}

.security-header h1 {
  font-size: 28px;
  font-weight: 600;
  color: #333;
  margin: 0 0 10px 0;
}

.security-subtitle {
  color: #666;
  font-size: 16px;
  margin: 0;
}

.security-section {
  margin-bottom: 40px;
  padding-bottom: 30px;
  border-bottom: 1px solid #e0e0e0;
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  color: #333;
  margin: 0 0 20px 0;
}

.security-item {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.security-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.security-item-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 500;
  color: #333;
}

.security-item-desc {
  color: #666;
  font-size: 14px;
  margin: 0 0 10px 0;
}

.security-item-value {
  color: #333;
  font-size: 14px;
  margin: 0;
}

.el-icon {
  font-size: 20px;
  color: #333;
}

.custom-button {
  border: 1px solid #333;
  color: #333;
  background: transparent;
  transition: all 0.3s ease;
}

.custom-button:hover {
  background: #333;
  color: #fff;
}

.custom-button.danger {
  border-color: #333;
  color: #333;
}

.custom-button.danger:hover {
  background: #333;
  color: #fff;
}

:deep(.el-switch.is-checked .el-switch__core) {
  border-color: #333;
  background-color: #333;
}

:deep(.el-switch__core) {
  border-color: #333;
}

:deep(.el-switch__label) {
  color: #333;
}

:deep(.el-switch__label.is-active) {
  color: #333;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .security-center {
    padding: 20px 15px;
  }

  .security-header h1 {
    font-size: 24px;
  }

  .security-item {
    padding: 15px;
  }

  .security-item-title {
    font-size: 14px;
  }

  .security-item-desc {
    font-size: 12px;
  }
}
</style> 